package com.sip.dbadapter.dao.impl;

import java.io.Serializable;
import java.util.List;

import com.sip.dbadapter.dao.domain.SystemInfo;
import com.sip.dbadapter.dao.interfaces.SystemInfoDao;



public class SystemInfoDaoImpl extends BusinessDaoImpl<SystemInfo, Serializable> implements SystemInfoDao {

 

    @Override
    protected Class<SystemInfo> getDomainClass() {
        return SystemInfo.class;
    }

    @Override
    public List<Object> getSystemData(String propertyName) {

        List<Object> apiDefinitionDataList = (List<Object>) exec("select distinct A." + propertyName + " from " + getDomainClass().getName() + " A");

        return apiDefinitionDataList;
    }

    @Override
    public List<Object[]> getSystemData(String[] propertyName) {

        String propertyString = getPropertyStringValue(propertyName);

        System.out.println("==>" + "select " + propertyString + " from " + getDomainClass().getName() + " A");
        List<Object[]> apiDefinitionDataList = (List<Object[]>) exec("select " + propertyString + " from " + getDomainClass().getName() + " A");
        return apiDefinitionDataList;
    }


    
    private String getPropertyStringValue(String[] propertyName) {

        String propertyString = "";
        for (String object : propertyName) {
            if (propertyName.length == 1) {
                propertyString = "A." + object + " ";
            } else {
                propertyString += ",  A." + object;
            }
        }
        if (propertyName.length > 1) {
            propertyString = propertyString.substring(1);
        }

        return propertyString;
    }


}
